#include <iostream>
#include <stack>
#include <vector>
using namespace std;

class Solution {
public:
    bool IsPopOrder(vector<int> pushV,vector<int> popV) {
        if (pushV.size() != popV.size()) {
            return false;
        }
        stack<int> s;
        auto p = popV.begin();
        for (int num: pushV) {
            s.push(num);
            while (!s.empty() && s.top() == *p) {
                s.pop();
                ++p;
            }
        }
        return s.empty();
    }
};


int main() {
    cout << Solution().IsPopOrder({1, 2, 3, 4, 5}, {4, 5, 3, 2, 1}) << endl;
    cout << Solution().IsPopOrder({1, 2, 3, 4, 5}, {4, 3, 5, 1, 2}) << endl;
    return 0;
}